<template>
	<view class="back-view" @touchmove.stop.prevent="moveHandle">
		<view class="view-background"></view>
		<view class="white-view-back">
			<view class="top-back">
				<view class="top-name">{{pageTitle}}</view>
				<view class="close-back" @click="closeBtnAction">
					<image class="close-img" src="../../../static/close.png"></image>
				</view>
			</view>
			<view class="top-line"></view>

			<scroll-view scroll-y="true" style="width: 560px;height: 400px;">
				<rich-text class="rich_text" v-if="introduceText !== '<p><br></p>'" :nodes="introduceText"> </rich-text>
			</scroll-view>
			<view class="bottom-back">
				<view class="bottom-btn" v-if="editType == 'contact'" @click="clickMessageAction">留言</view>
				<view class="bottom-btn" v-if="editType == 'about'" @click="clickAboutAction">确定</view>
				<view class="bottom-btn" v-if="editType == 'smallPage'" @click="closeBtnAction">确定</view>
			</view>
		</view>
		<leaveMessage v-if="showLeaveMessage" @leaveMessageClose='clickLeaveMessageClose'></leaveMessage>
	</view>
</template>

<script>
	import leaveMessage from "@/packageC/PhonePC/info/leaveMessage.vue"
	export default {
		components: {
			leaveMessage
		},
		props: {
			editType: {
				type: String,
				default: 'contact', //contact：联系 about：关于
			},
			selectID: {
				type: String,
				default: '',
			}
		},
		data() {
			return {
				pageTitle: "联系起航",
				showLeaveMessage: false,
				contactUs: {},
				introduceText: '', // 活动介绍的富文本内容
			}
		},
		mounted() {
			if (this.editType == 'contact') {
				this.pageTitle = '联系起航'
				this.requestContactData();
			} else if (this.editType == 'about') {
				this.pageTitle = '关于起航'
				this.requestAboutData()
			} else if (this.editType == 'smallPage') {
				this.pageTitle = '微页面'
				this.requestSmallPageData()
			}

		},
		methods: {
			//关于我们信息网络请求
			async requestAboutData() {
				let _this = this
				const res = await this.$myRequest({
					url: '/client/news/aboutUs',
					method: 'GET',
				})
				console.log('返回结果', res)
				if (res.data.code == 200) {
					_this.contactUs = res.data.data;
					_this.introduceText = _this.richText(_this.contactUs.intro);
				}
			},
			//联系我们信息网络请求
			async requestContactData() {
				let _this = this
				const res = await this.$myRequest({
					url: '/admin/news/contactUs',
					method: 'GET',
				})
				console.log('返回结果', res)
				if (res.data.code == 200) {
					_this.contactUs = res.data.data;
					_this.introduceText = _this.richText(_this.contactUs.intro);
				}
			},
			//微页面
			async requestSmallPageData() {
				let _this = this
				const res = await this.$myRequest({
					url: '/admin/news/' + this.selectID,
					method: 'GET',
				})
				console.log('返回结果', res)
				if (res.data.code == 200) {
					_this.contactUs = res.data.data;
					_this.introduceText = _this.richText(_this.contactUs.intro);
				}
			},
			// 解析富文本后显示数据
			richText(richTextData) {
				if (richTextData) {
					var richtext = richTextData;
					const regex = new RegExp('<img', 'gi');
					const regex2 = new RegExp('src="/api', 'gi');
					richtext = richtext.replace(regex2, `src="${this.$ServerBaseUrl}/api`);
					richtext = richtext.replace(regex, `<img style="max-width: 100%;"`);
					return richtext;
				} else {
					return '';
				}
			},
			clickAboutAction() {
				this.$emit('aboutClose')
			},
			closeBtnAction() {
				if (this.editType == 'contact') {
					this.$emit('contactClose')
				} else if (this.editType == 'about') {
					this.$emit('aboutClose')
				} else if (this.editType == 'smallPage') {
					this.$emit('smallPageClose')
				}
			},
			moveHandle() {
				return true
			},
			clickMessageAction() {
				this.showLeaveMessage = true;
			},
			clickLeaveMessageClose() {
				this.showLeaveMessage = false;

			}
		},
	}
</script>

<style>
	.back-view {
		position: fixed;
		top: 0;
		right: 0;
		bottom: 0;
		left: 0;
		z-index: 199;
		display: flex;
		justify-content: center;
		align-items: center;
	}

	.view-background {
		position: absolute;
		width: 100%;
		height: 100%;
		z-index: 100;
		background-color: rgba(0, 0, 0, 0.3);
	}

	.white-view-back {
		width: 552px;
		height: 500px;
		padding: 24px;
		max-height: 500px;
		background-color: white;
		margin-top: -50px;
		border-radius: 4px;
		z-index: 101;
		position: absolute;
	}

	.top-back {
		display: flex;
		justify-content: space-between;
	}

	.top-name {
		font-size: 18px;
		font-weight: normal;
		color: #333333;

	}

	.close-back {
		cursor: pointer;
		width: 20px;
		height: 20px;
		display: flex;
		justify-content: center;
		align-items: center;
	}

	.close-img {
		width: 12px;
		height: 12px;
	}

	.top-line {
		height: 1px;
		background: #EEEEEE;
		width: 100%;
		margin-top: 20px;
		margin-bottom: 20px;
	}

	.bottom-back {

		bottom: 0px;
		width: 100%;
		display: flex;
		justify-content: flex-end;
		align-items: center;
		position: absolute;
		height: 60px;
		right: 16px;
	}

	.bottom-btn {
		cursor: pointer;
		width: 104px;
		height: 32px;
		background: #2DA9C5;
		border-radius: 2px;
		color: #FFFFFF;
		font-size: 14px;
		display: flex;
		justify-content: center;
		align-items: center;
	}
</style>
